<!DOCTYPE html
		 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Insert Snippet</title>
<link rel="stylesheet" type="text/css" href="../../../popups/popup.css" />
<link rel="stylesheet" type="text/css" href="../InsertSnippet.css" />
<script type="text/javascript" src="../../../popups/popup.js"></script>
<script type="text/javascript">

var InsertSnippet = window.opener.InsertSnippet;
var editor = null;


function Init() {
	__dlg_translate("InsertSnippet");
	__dlg_init(null, {width:800,height:600});

	var config = window.dialogArguments;
 
	var snippets = config.snippets;
	
	if ( config.pageStyle && !Xinha.is_ie)
    {
		var style = document.createElement("style");
		style.type = "text/css";
		style.innerHTML = config.pageStyle;
		document.getElementsByTagName("HEAD")[0].appendChild(style);
    }
    
	if ( typeof config.pageStyleSheets !== 'undefined' )
	{
		for ( var i = 0; i < config.pageStyleSheets.length; i++ )
		{
			var style = document.createElement("link");
			style.type = "text/css";
			style.rel = 'stylesheet';
			style.href =	config.pageStyleSheets[i];
			document.getElementsByTagName("HEAD")[0].appendChild(style);
		}
	}
		
	var tbody = document.getElementById("snippettable");
	var snippet_html;
	var snippet_name;
	var trow;
	for(var i = 0; i < snippets.length; i++) 
	{
		trow = tbody.insertRow(i);
		snippet_html = snippets[i]['HTML'];
		snippet_name = snippets[i]['id'];
	 
		var insertAsVariable = '';
		if (config.InsertSnippet.showInsertVariable)
		{
			insertAsVariable = ' | <a href="javascript:onOK('+i+','+'\'variable\''+')">'+Xinha._lc("Variable","InsertSnippet")+'</a>';
		}
		var new_cell = trow.insertCell(0);
		new_cell.innerHTML = snippet_name +': '+Xinha._lc("Insert as","InsertSnippet")+' <a href="javascript:onOK('+i+','+'\'html\''+')">HTML</a>'+insertAsVariable + ' (<a id="show_preview'+i+'" href="javascript:preview(\'show\','+i+')">'+Xinha._lc("Show preview","InsertSnippet")+'</a>)<div id="preview'+i+'" style="display:none">'+snippets[i]['HTML']+'</div>'; 
		new_cell.id = 'cell' + i;
			
	}

	document.body.onkeypress = __dlg_key_press;
}

function preview(action,i) {
	var show_preview_link = document.getElementById('show_preview'+i); 
	switch(action)
	{
		case 'show':
			document.getElementById('preview'+i).style.display = 'block';
			show_preview_link.innerHTML = Xinha._lc("Hide preview","InsertSnippet");
			show_preview_link.href = "javascript:preview('hide','"+i+"');";
			
		break;
		case 'hide':
			document.getElementById('preview'+i).style.display = 'none';
			show_preview_link.innerHTML = Xinha._lc("Show preview","InsertSnippet");
			show_preview_link.href = "javascript:preview('show','"+i+"');";
		break;
	}
}
function onCancel() {
	__dlg_close(null);
	return false;
}

function onOK(snippetnum,how) {
	var params = new Object();
	params["snippetnum"] = snippetnum;
	params["how"] = how;
	__dlg_close(params);
	return false;
}

function __dlg_key_press(ev) {
	ev || (ev = window.event);
	switch(ev.keyCode) {
		case 13:
		document.getElementById('bt_ok').click();
			break;
		case 27:
		__dlg_close();
		return false;
	}
return true;
}
</script>

<style type="text/css">
body {margin:0 !IMPORTANT;padding:0 !IMPORTANT;}
.buttons {border-top: 1px solid #999; padding: 5px; text-align: right; height: 20px; }
td {background:white;padding:5px;border:1px solid;border-color: ButtonHighlight ButtonShadow ButtonShadow ButtonHighlight;}
.preview {}
</style>
</head>
<body class="dialog" onload="Init()">
<form action="" method="get">
  <div class="title" >Insert Snippet</div>
  <div style="height:470px;overflow:auto;">
  <table style="border: 0; width: 100%;" id="snippettable">
  </table>
  </div>
<div class="space"></div>
<div class="buttons">
<button type="button" onclick="return onCancel();">Cancel</button>
</div>
</form>
</body>
</html>